/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package system.handlers.admincommands;

import aionjHungary.geoEngine.models.GeoMap;

import com.aionemu.gameserver.geoEngine.GeoEngine;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;
import com.aionemu.gameserver.utils.chathandlers.AdminCommandChatHandler;

/**
 * @author Mr. Poke
 *
 */
public class Geo extends AdminCommand
{

	/**
	 * @param commandName
	 */
	protected Geo()
	{
		super("geo");
	}

	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.utils.chathandlers.AdminCommand#executeCommand(com.aionemu.gameserver.model.gameobjects.player.Player, java.lang.String[])
	 */
	@Override
	public void executeCommand(Player admin, String[] params)
	{
		if (admin.getAccessLevel() < 3)
		{
			PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
			return;
		}
		if (params.length != 1)
		{
			PacketSendUtility.sendMessage(admin, "syntax //geo target | z ");
			return;
		}
		if (params[0].equalsIgnoreCase("target"))
		{
			if (admin.getTarget() == null)
			{
				PacketSendUtility.sendMessage(admin, "No have target!");
				return;
			}
			GeoMap geoMap = GeoEngine.getInstance().getGeoMapByWorldId(admin.getWorldId());
			if (geoMap == null)
			{
				PacketSendUtility.sendMessage(admin, "No geodata!");
				return;
			}
			if (geoMap.canSee(admin.getX(),admin.getY(),admin.getZ(), admin.getTarget().getX(),admin.getTarget().getY(),admin.getTarget().getZ()))
				PacketSendUtility.sendMessage(admin,"See");
			else
				PacketSendUtility.sendMessage(admin,"Dont see");
		}
		else if (params[0].equalsIgnoreCase("z"))
		{
			float z = GeoEngine.getInstance().getZ(admin.getWorldId(), admin.getX(),admin.getY(),admin.getZ());
			PacketSendUtility.sendMessage(admin, "Z: "+z);
		}
	}

	public static void main(String[] args)
	{
		AdminCommandChatHandler.getInstance().registerAdminCommand(new Geo());
	}
}
